package com.ten.system.controller;

import com.ten.common.core.entity.AclPermission;
import com.ten.security.utils.OssUtils;
import com.ten.system.service.AclPermissionService;
import com.ten.common.core.vo.Result;
import com.ten.system.vo.FenPermissionVo;
import com.ten.system.vo.PermissionVo;
import com.ten.system.vo.RoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author ：Q大侠
 * @date ：Created in 2022/12/1 22:44
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/system/permission")
@Api(tags = "权限接口类")
public class AclPermissionController {

    @Autowired
    private AclPermissionService permissionService;

    @GetMapping("getByUserid/{userid}")
    @ApiOperation(value = "根据用户id查询具有的权限")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(value = "用户名id",name = "userid")
            }
    )
    public Result<AclPermission> getByUserid(@PathVariable String userid){
        return permissionService.findByUserId(userid);
    }
    /** 
     * @create by:  Q大侠
     * @description: 获取菜单目录 
     * @create time: 2022/12/4 7:08
      * @param  
     * @return  Result<List<AclPermission>>
     */
    @GetMapping("getAllPermission")
    public Result<List<AclPermission>> getAllPermission(){
        return permissionService.findByUsername();
    }
    /** 
     * @create by:  Q大侠
     * @description:  
     * @create time: 2022/12/7 21:03
      * @param
     * @return  
     */
    @GetMapping("findPermissionByRoleId/{roleId}")
    @ApiOperation(value = "根据角色id查询具有的权限")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(value = "角色id",name = "roleId")
            }
    )
    public Result<Map<String,Object>> findPermissionByRoleId(@PathVariable String roleId){
        return permissionService.findAll(roleId);
    }

    @PostMapping("/confirmFenPermission")
    public Result confirmFenPermission(@RequestBody FenPermissionVo fenPermissionVo){
        return permissionService.confirmFenPermission(fenPermissionVo);
    }

    @PostMapping("findAllByPage/{currentPage}/{pageSize}")
    @ApiOperation(value = "菜单管理初始分页")
    @ApiImplicitParams({@ApiImplicitParam(name = "currentPage",value = "当前页码"),
                        @ApiImplicitParam(name = "pageSize",value = "每页显示的条数")})
    public Result findAllByPage(@RequestBody PermissionVo permissionVo,
                                @PathVariable Integer currentPage,
                                @PathVariable Integer pageSize){
        return permissionService.findAllByPage(permissionVo,currentPage,pageSize);
    }
    @PutMapping("insert")
    @ApiOperation(value = "菜单/目录新增")
    public Result insert(@RequestBody AclPermission aclPermission){
        return permissionService.insert(aclPermission);
    }

    @PostMapping("/deleteById/{ids}")
    @ApiOperation(value = "按照ids删除")
    @ApiImplicitParams({@ApiImplicitParam(name = "ids",value = "要删除的id及其子目录id")})
    public Result deleteById(@PathVariable List ids){
        return permissionService.deleteByIds(ids);
    }

    @PostMapping("update")
    @ApiOperation(value = "修改主菜单")
    public Result update(@RequestBody AclPermission aclPermission){
        return permissionService.update(aclPermission);
    }


}
